package main

import (
	"encoding/json"
	"lesson/api/handler"
	"lesson/config"
	"lesson/inits"
	"lesson/internal/queue"

	"log"
)

type Test1 struct {
	Test2 string `json:"test2"`
	Test3 string `json:"test3"`
	Test4 string `json:"test4"`
}

func main() {
	config.InitViper()
	inits.InitMysql()
	inits.InitRabbitMq()

	msgs := queue.PublishSub("publishTest")

	forever := make(chan bool)
	//启用协程处理消息
	go func() {
		for d := range msgs {
			//消息逻辑处理，可以自行设计逻辑
			log.Printf("Received a message: %s", d.Body)
			var data handler.Datas
			json.Unmarshal(d.Body, &data)
			handler.WSRespSuccess(data.OnlineConn, data.Message)
		}
	}()

	log.Printf(" [*] Waiting for messages. To exit press CTRL+C")
	<-forever
}
